package web;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import bus.PersonManager;
import bus.ProductManager;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SpringappController implements Controller
{
	private ProductManager prodMan;
	private PersonManager personMan;
	public ProductManager getProductManager() {
		return prodMan;
	}

	public void setProductManager(ProductManager prodMan) {
		this.prodMan = prodMan;
	}

	public ModelAndView handleRequest( HttpServletRequest request, HttpServletResponse response )
		throws ServletException, IOException
	{
		String now = ( new java.util.Date() ).toString();
		//prodMan = new ProductManager();// fix null-pointer exception??
		
		Map myModel = new HashMap();
		myModel.put( "now", now );
		myModel.put( "products", getProductManager().getProducts() );
		myModel.put("people", getPersonMan().getPeople());
		return new ModelAndView( "hello", "model", myModel );
	}

	public PersonManager getPersonMan() {
		return personMan;
	}

	public void setPersonMan(PersonManager personMan) {
		this.personMan = personMan;
	}

}
